package com.google.product.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * 创建队列，交换机，延迟队列，绑定关系 的configuration
 * 不会重复创建覆盖
 * 1、第一次使用队列【监听】的时候才会创建
 * 2、Broker没有队列、交换机才会创建
 */
@Configuration
public class MyDelayQueueConfig {

    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("goods-exchange",true,false);
    }

    @Bean
    public Queue queue(){
        return new Queue("goods-save-mysql");
    }

    @Bean
    public Queue queue2(){
        return new Queue("goods-save-es");
    }
    @Bean
    public Queue queue3(){
        return new Queue("goods-update-mysql");
    }

    @Bean
    public Queue queue4(){
        return new Queue("goods-update-es");
    }
    @Bean
    public Queue queue5(){
        return new Queue("goods-delete-mysql");
    }

    @Bean
    public Queue queue6(){
        return new Queue("goods-delete-es");
    }

    @Bean
    public Binding binding(){
//        return BindingBuilder.bind(queue).to(topicExchange).with("product.mysql.*");
        return BindingBuilder.bind(new Queue("goods-save-mysql")).to(new TopicExchange("goods-exchange")).with("goods.save.mysql");
    }

    @Bean
    public Binding binding2(){
        return BindingBuilder.bind(new Queue("goods-save-es")).to(new TopicExchange("goods-exchange")).with("goods.save.es");
    }
    @Bean
    public Binding binding3(){
//        return BindingBuilder.bind(queue).to(topicExchange).with("product.mysql.*");
        return BindingBuilder.bind(new Queue("goods-update-mysql")).to(new TopicExchange("goods-exchange")).with("goods.update.mysql");
    }

    @Bean
    public Binding binding4(){
        return BindingBuilder.bind(new Queue("goods-update-es")).to(new TopicExchange("goods-exchange")).with("goods.update.es");
    }

    @Bean
    public Binding binding5(){
//        return BindingBuilder.bind(queue).to(topicExchange).with("product.mysql.*");
        return BindingBuilder.bind(new Queue("goods-delete-mysql")).to(new TopicExchange("goods-exchange")).with("goods.delete.mysql");
    }

    @Bean
    public Binding binding6(){
        return BindingBuilder.bind(new Queue("goods-delete-es")).to(new TopicExchange("goods-exchange")).with("goods.delete.es");
    }
}
